package com.game.dongzhao;

import com.game.dongzhao.bean.Player;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.IOException;

public class DongZhaoApplication extends Application {
    /**
     * System.Logger
     */
    public static System.Logger logger = System.getLogger("DongZhaoLog");
    /**
     * 当前stage
     */
    public static Stage currentStage;

    /**
     * 继承自Application启动方法
     *
     * @param stage
     * @throws IOException
     */
    @Override
    public void start(Stage stage) throws IOException {
        // 禁止縮放
        stage.setResizable(false);
        this.setCurrentStage(stage);
        this.changeView("揭秘东赵遗址-开始游戏", "start-view.fxml");
        // 初始化玩家信息
        Player.initializePlayer();
    }

    /**
     * 新打开窗口的方法
     * @param stage
     * @param titleName
     * @param fxmlName
     * @throws IOException
     */
    public void start(Stage stage,String titleName,String fxmlName) throws IOException {
        // 默认不可用縮放
        stage.setResizable(true);
        this.setCurrentStage(stage);
        this.changeView(titleName, fxmlName);
        // 初始化玩家信息
        Player.initializePlayer();
    }

    /**
     * 切换页面
     *
     * @param titleName 标题
     * @param fxmlName  页面文件
     * @throws IOException
     */
    public void changeView(String titleName, String fxmlName) throws IOException {
        logger.log(System.Logger.Level.INFO,"转换界面到"+fxmlName);
        FXMLLoader fxmlLoader = new FXMLLoader(DongZhaoApplication.class.getResource(fxmlName));
        Scene scene = new Scene(fxmlLoader.load());
        this.getCurrentStage().setTitle(titleName);
        this.getCurrentStage().setScene(scene);
        this.getCurrentStage().show();
    }

    public static void main(String[] args) {
        launch();
    }

    public Stage getCurrentStage() {
        return currentStage;
    }

    public void setCurrentStage(Stage currentStage) {
        this.currentStage = currentStage;
    }
}